local RoleRevive = require("role.RoleRevive")
local DropLogic  = require("monster.DropLogic")
local RoleUIControl = require("role.RoleUIControl")
local Msg = require("core.Msg")
local ObjHuman = require("core.ObjHuman")
local RoleExcel = require("excel.Role")
local InnerDataManagerFL = require("innerdata.InnerDataManagerFL")
local InnerDataDefine = require("innerdata.Define")
local RoleFFI = require("role.RoleFFI")
local BagLogic = require("bag.BagLogic")
local ItemDefine = require("bag.ItemDefine")
local ItemDefine = require("bag.ItemDefine")

function CG_REVIVE_NOW(human)
    RoleRevive.reviveNow(human)
end

function CG_REVIVE_GO_HOME(human, isServer)
    RoleRevive.reviveGoHome(human, isServer)
end

function CG_PICK_UP_ITEM(human, msg)
    DropLogic.pickUpItem(human, msg.obj_id)
end

function CG_HUMAN_SET(human, msg)
    human.db.humanSet = msg.reminder
    ObjHuman.sendHumanSet(human)
end

function CG_LINE1_FN_ICON_LIST(human)
    RoleUIControl.sendLine1FnIcon(human)
end

function CG_PREKNOW_INFO(human)
    RoleUIControl.sendPreknow(human)
end
function CG_ROLE_COMBAT_MODE()--human, msg)

end

function CG_ROLE_KEY_SET(human)
    local sendMsg = Msg.gc.GC_ROLE_KEY_SET
    sendMsg.detail = RoleExcel.keySet[1].detail
    Msg.send(sendMsg, human.fd)
end

function CG_HANG_SETTING(human, msg)
    human.db.autoUseDrugPer = msg.percent
    ObjHuman.sendAutoUseDrugPer(human)
end

function CG_SET_MEDICINE_SKILL(human, msg)
    local nIndex = msg.index
    if nIndex >= 0 and nIndex <= 1 then
        local nItemID = msg.skillItemList
        if ItemDefine.isItem(nItemID) then
            human.db.skillItemList[nIndex] = msg.skillItemList
            ObjHuman.sendSkillItemList(human)
        end
    end
end

function W2LProcess(human, oType, oData)
    if oData.type == 1 then
        if oData.updateYuanbao > 0 then
            ObjHuman.addYuanbao(human, oData.updateYuanbao, oData.logtype)
        elseif oData.updateYuanbao < 0 then
            ObjHuman.decYuanbao(human, math.abs(oData.updateYuanbao), oData.logtype)
        end
    elseif oData.type == 2 then
        if oData.updateYuanbao > 0 then
            ObjHuman.addBindYuanbao(human, oData.updateYuanbao, oData.logtype)
        elseif oData.updateYuanbao < 0 then
            ObjHuman.decBindYuanbao(human, math.abs(oData.updateYuanbao), oData.logtype)
        end
    end
end

function changeName(human, oType, oData)
    if oData.type == 1 then
        if BagLogic.getItemCount(human, ItemDefine.ITEM_ID_GAIMINGKA) < 1 then
            return
        end
        BagLogic.delItemsById(human, ItemDefine.ITEM_ID_GAIMINGKA, 1, "item_use")
        InnerDataManagerFL.Send2WInnerData(human, InnerDataDefine.INNERDATA_TYPE_CHANGE_NAME, {name = oData.name})
        ObjHuman.onlineHuman[human.name] = nil
        human.name = RoleFFI.ffi_string(oData.name)
        ObjHuman.onlineHuman[oData.name] = human
    end  
end

InnerDataManagerFL.Register(InnerDataDefine.INNERDATA_TYPE_CHANGE_NAME, changeName)
InnerDataManagerFL.Register(InnerDataDefine.INNERDATA_TYPE_ROLE, W2LProcess)
